package com.shenmazong.serveredustudent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.serveredustudent.pojo.TbCollage;
import com.shenmazong.serveredustudent.service.TbCollageService;
import com.shenmazong.serveredustudent.mapper.TbCollageMapper;
import com.shenmazong.utils.ResultResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class TbCollageServiceImpl extends ServiceImpl<TbCollageMapper, TbCollage>
    implements TbCollageService{

    @Autowired
    private TbCollageMapper collageMapper;

    @Override
    public ResultResponse getAllCollage() {

        List<TbCollage> tbCollages = collageMapper.selectList(null);

        return ResultResponse.SUCCESS(tbCollages);
    }

    @Override
    public ResultResponse getCollageByCollageId(long collageId) {

        if(collageId==0){
            return ResultResponse.FAILED(-1,"参数异常");
        }

        LambdaQueryWrapper<TbCollage> last = new QueryWrapper<TbCollage>().lambda().eq(TbCollage::getCollageId, collageId).last("limit 1");

        TbCollage tbCollage = collageMapper.selectOne(last);

        return ResultResponse.SUCCESS(tbCollage);
    }
}




